package com.cskaoyan.market.controller;

import com.cskaoyan.market.db.domain.MarketFeedback;
import com.cskaoyan.market.service.AdminFeedbackService;
import com.cskaoyan.market.service.impl.AdminFeedbackServiceImpl;
import com.cskaoyan.market.util.JacksonUtil;
import com.cskaoyan.market.util.ResponseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/admin/feedback/*")
public class AdminFeedbackController extends HttpServlet {

    AdminFeedbackService adminFeedbackService =new AdminFeedbackServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String requestURI = req.getRequestURI();
        String op = requestURI.replace(req.getContextPath() + "/admin/feedback/", "");

        if ("list".equals(op)){
            list(req, resp);
        }

    }

    private void list(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String id = req.getParameter("id");
        String username = req.getParameter("username");
        String phoneNumber = req.getParameter("phone number");
        String feedback = req.getParameter("feedback");
        String page = req.getParameter("page");
        String time = req.getParameter("time");
        String limit = req.getParameter("limit");

        List<MarketFeedback> feedbackList = adminFeedbackService.list(id, username, phoneNumber, feedback, page, time, limit);

        Object o = ResponseUtil.okList(feedbackList);
        String s = JacksonUtil.getObjectMapper().writeValueAsString(o);
        resp.getWriter().println(s);

    }
}
